package controller;

import implementor.CategoryImp;

import implementor.MaterialImp;
import implementor.PurchaseImp;
import implementor.SellerInfoImp;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.table.DefaultTableModel;

import daoInterface.CategoryDao;

import daoInterface.MaterialDao;
import daoInterface.PurchaseDao;
import daoInterface.SellerInfoDao;

import dto.Purchase;

import model.Category;
import model.Material;
import model.SellerInfo;


import utilities.ViewUtilites;
import views.StockReport;

public class StockReportController implements ActionListener
{
	StockReport view;
	Material model;
	
	public StockReportController() 
	{
		
	}

	


	public StockReportController(StockReport view, Material model) {
		super();
		this.view = view;
		this.model = model;
		view.actionListener(this);
	}


	

	public StockReport getView() {
		return view;
	}




	public void setView(StockReport view) {
		this.view = view;
	}




	
	
	public Material getModel() {
		return model;
	}




	public void setModel(Material model) {
		this.model = model;
	}




	public void setComboLevel0()
	{
		Level0Dao ld=new Level0Imp();
		Level0[] level0=ld.retrieveAll();
		String[] items=new String[level0.length];
		for(int i=0;i<items.length;i++)
			{
				items[i]=level0[i].getLevelName0();
			}
			
		ViewUtilites.set_comboBox(view.getLevel0Combo(), items);
	}
	
	public void setComboLevel1()
	{
		Level1Dao ld=new Level1Imp();
		Level1[] level1=ld.retrieveAll();
		String[] items=new String[level1.length];
		for(int i=0;i<items.length;i++)
			{
				items[i]=level1[i].getLevelName1();
			}
			
		ViewUtilites.set_comboBox(view.getLevel1Combo(), items);
	}
	
	public void setComboLevel2()
	{
		Level2Dao ld=new Level2Imp();
		Level2[] level2=ld.retrieveAll();
		String[] items=new String[level2.length];
		for(int i=0;i<items.length;i++)
			{
				items[i]=level2[i].getLevelName2();
			}
			
		ViewUtilites.set_comboBox(view.getLevel2Combo(), items);
	}
	
	public void setComboLevel3()
	{
		Dao ld=new Level3Imp();
		Level3[] level3=ld.retrieveAll();
		String[] items=new String[level3.length];
		for(int i=0;i<items.length;i++)
			{
				items[i]=level3[i].getlevelName3();
			}
			
		ViewUtilites.set_comboBox(view.getLevel3Combo(), items);
	}
	
	public void setComboSeller()
	{
		SellerInfoDao seller=new SellerInfoImp();
		SellerInfo[] array=seller.retrieveAll();
		String[] items=new String[array.length];
		for(int i=0;i<items.length;i++)
		{
			items[i]=array[i].getSellerName();
		}
		ViewUtilites.set_comboBox(view.getSellerNameCombo(), items);
	}

	
	@Override
	public void actionPerformed(ActionEvent ar) 
	{
		String level0=view.getLevel0Combo().getSelectedItem().toString();
		String level1=view.getLevel1Combo().getSelectedItem().toString();
		String level2=view.getLevel2Combo().getSelectedItem().toString();
		String level3=view.getLevel3Combo().getSelectedItem().toString();
		String seller=view.getSellerNameCombo().getSelectedItem().toString();
		
		SellerInfoDao sellerimp=new SellerInfoImp();
		SellerInfo sel=sellerimp.retrieve("sellerName", seller);
		
		PurchaseDao purchase=new PurchaseImp();
		Purchase pur=purchase.retrieve("sellerId",sel.getSellerId()+"");
		
		CategoryDao cat=new CategoryImp();
		Category category=cat.retrieveOnMultipleCond(level0, level1, level2, level3);
		
		MaterialDao material=new MaterialImp();
		Material[] mat=material.retrieveArray("catCode", category.getCatCode());
		
		for(int i=0;i<mat.length;i++)
		{
			Material temp=mat[i];
			if((temp.getPurchaseId()==pur.getPurchaseId()))
			{
				      // ADD IN TABLE;
			}
		}
		
		
		
		
		
		
	}
	

}
